use sea_orm_migration::prelude::*;

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager
            .create_table(
                Table::create()
                    .table(BrandTranslation::Table)
                    .if_not_exists()
                    .col(
                        ColumnDef::new(BrandTranslation::Id)
                            .uuid()
                            .not_null()
                            .primary_key(),
                    )
                    .col(ColumnDef::new(BrandTranslation::BrandId).uuid().not_null())
                    .col(ColumnDef::new(BrandTranslation::LanguageCode).string().not_null())
                    .col(ColumnDef::new(BrandTranslation::Name).string().not_null())
                    .col(ColumnDef::new(BrandTranslation::Description).string())
                    .col(ColumnDef::new(BrandTranslation::CreatedAt).timestamp_with_time_zone().not_null())
                    .col(ColumnDef::new(BrandTranslation::UpdatedAt).timestamp_with_time_zone().not_null())
                    .foreign_key(
                        ForeignKey::create()
                            .name("fk-brand_translation-brand_id")
                            .from(BrandTranslation::Table, BrandTranslation::BrandId)
                            .to(Brand::Table, Brand::Id)
                            .on_delete(ForeignKeyAction::Cascade),
                    )
                    .to_owned(),
            )
            .await
    }

    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager
            .drop_table(Table::drop().table(BrandTranslation::Table).to_owned())
            .await
    }
}

#[derive(DeriveIden)]
enum Brand {
    Table,
    Id,
}

#[derive(DeriveIden)]
enum BrandTranslation {
    Table,
    Id,
    BrandId,
    LanguageCode,
    Name,
    Description,
    CreatedAt,
    UpdatedAt,
}